package com.zp.self.module.level_5_设计模式.创建型模式.Ⅱ_工厂方法.枚举工厂;

public enum CoffeeEnumFactory {
    AmericanCoffee(new AmericanCoffee()),
    LatteCoffee(new LatteCoffee());

    private final Coffee coffee;
    CoffeeEnumFactory(Coffee coffee) {
        this.coffee = coffee;
    }

    public static Coffee match(String type) {
        try {
            CoffeeEnumFactory coffeeEnumFactory = CoffeeEnumFactory.valueOf(type);
            return coffeeEnumFactory.coffee;
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("没有你需要的类型！",e);
        }
    }
}
